package com.naiterui.ehp.bs.cms.common.utils;

import java.math.BigDecimal;

/**
 * 报告日期工具类
 * 
 * @author yangfuya
 * @since 2022/2/22
 */
public class ReportUtil {
    public static final int TYPE_YEAR = 1;
    public static final int TYPE_MONTH = 2;
    public static final int TYPE_DAY = 3;
    public static final String DATE_YEAR = "%Y";
    public static final String DATE_MONTH = "%Y-%m";
    public static final String DATE_DAY = "%Y-%m-%d";
    public static final String DATE_SINGLE_MONTH = "%m";
    public static final String DATE_SINGLE_DAY = "%d";

    /**
     * 获取报告格式化
     * 
     * @param reportType
     * @return
     */
    public static String getDateFormat(Integer reportType) {
        if (reportType == TYPE_YEAR) {
            return DATE_YEAR;
        } else if (reportType == TYPE_MONTH) {
            return DATE_YEAR;
        }
        return DATE_MONTH;
    }

    /**
     * 获取类型格式化
     * 
     * @param reportType
     * @return
     */
    public static String getTypeFormat(Integer reportType) {
        if (reportType == TYPE_YEAR) {
            return DATE_YEAR;
        } else if (reportType == TYPE_MONTH) {
            return DATE_MONTH;
        }
        return DATE_DAY;
    }

    /**
     * 获取报告类型格式化
     *
     * @param reportType
     * @return
     */
    public static String getReportTypeFormat(Integer reportType) {
        if (reportType == TYPE_YEAR) {
            return DATE_YEAR;
        } else if (reportType == TYPE_MONTH) {
            return DATE_SINGLE_MONTH;
        }
        return DATE_SINGLE_DAY;
    }

    /**
     * 获取环比
     * 
     * @param today
     * @param yesterday
     * @return
     */
    public static BigDecimal getQoq(Integer today, Integer yesterday) {
        if (yesterday == null || yesterday == 0) {
            return BigDecimal.valueOf(0.0);
        }
        return BigDecimal.valueOf((today - yesterday) * 100).divide(BigDecimal.valueOf(yesterday), 2,
            BigDecimal.ROUND_HALF_DOWN);
    }

    /**
     * 获取分割的报告日期
     * 
     * @param reportType
     * @param reportDate
     * @return
     */
    public static String getSubReportDate(Integer reportType, String reportDate) {
        if (reportType == 1) {
            return reportDate.substring(0, 4);
        }
        if (reportType == 2) {
            return reportDate.substring(0, 7);
        }
        return reportDate;
    }

    /**
     * 分转元
     * 
     * @param price
     * @return
     */
    public static String changeF2Y(int price) {
        return BigDecimal.valueOf(Long.valueOf(price)).divide(new BigDecimal(100)).toString();
    }

}
